<?php

/**
 * This is the model class for table "user_data".
 *
 * The followings are the available columns in table 'user_data':
 * @property integer $user_data_ID
 * @property string $name
 * @property string $email
 * @property string $phone
 * @property string $location
 * @property string $avatar
 * @property string $workplace
 * @property string $description
 * @property string $rank
 * @property string $education1
 * @property string $education2
 * @property string $graduated1
 * @property string $graduated2
 * @property string $education_other
 * @property string $last_login
 *
 * The followings are the available model relations:
 * @property User[] $users
 */
class UserData extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return UserData the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user_data';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_data_ID', 'required'),
			array('user_data_ID', 'numerical', 'integerOnly'=>true),
			array('name, email, education1', 'length', 'max'=>100),
			array('phone, rank, education2', 'length', 'max'=>45),
			array('location, workplace', 'length', 'max'=>200),
			array('avatar, education_other', 'length', 'max'=>1000),
			array('description', 'length', 'max'=>4000),
			array('graduated1, graduated2', 'length', 'max'=>4),
			array('last_login', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_data_ID, name, email, phone, location, avatar, workplace, description, rank, education1, education2, graduated1, graduated2, education_other, last_login', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'users' => array(self::HAS_MANY, 'User', 'user_data_ID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_data_ID' => 'User Data',
			'name' => 'Name',
			'email' => 'Email',
			'phone' => 'Phone',
			'location' => 'Location',
			'avatar' => 'Avatar',
			'workplace' => 'Workplace',
			'description' => 'Description',
			'rank' => 'Rank',
			'education1' => 'Education1',
			'education2' => 'Education2',
			'graduated1' => 'Graduated1',
			'graduated2' => 'Graduated2',
			'education_other' => 'Education Other',
			'last_login' => 'Last Login',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_data_ID',$this->user_data_ID);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('location',$this->location,true);
		$criteria->compare('avatar',$this->avatar,true);
		$criteria->compare('workplace',$this->workplace,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('rank',$this->rank,true);
		$criteria->compare('education1',$this->education1,true);
		$criteria->compare('education2',$this->education2,true);
		$criteria->compare('graduated1',$this->graduated1,true);
		$criteria->compare('graduated2',$this->graduated2,true);
		$criteria->compare('education_other',$this->education_other,true);
		$criteria->compare('last_login',$this->last_login,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}